<?php include "menu.phtml"; ?>
<div id="right">
	<div class="rightbox">
		<div class="context"><div class="in"><a href="javascript:void(0);" id="context_menu" class="icon_link the_down"><span></span></a></div></div>
		<h1><?php echo $this->translate->_("Product Links"); ?></h1>
		<br />
		<?php if(isset($this->lk['errors']) && count($this->lk['errors']) > 0):?>
			<div class="c_error">
				<ul>
					<?php foreach($this->lk['errors'] as $idx => $error): ?>
						<li><b><?php echo $error; ?></b> (<?php echo $idx; ?>)</li>
					<?php endforeach; ?>
				</ul>
			</div>
			<br />
		<?php endif; ?>
		<form method="post" action="">
			<?php $all = unserialize($this->product->getLinks()); if(!$all) $all = array(); for($x = 1; $x <= 5; $x++) { $name = key($all); $link = current($all); ?>
				<div>
					<label for="item_name_<?php echo $x; ?>" class="optional"><?php echo sprintf($this->translate->_("Link %s"), $x); ?></label>
					<input type="text" class="name" name="item_name_<?php echo $x; ?>" id="item_name_<?php echo $x; ?>" style="width: 200px;" value="<?php echo isset($name) ? $name : $this->translate->_("Name"); ?>" />
					<input type="text" class="link" name="item_link_<?php echo $x; ?>" id="item_link_<?php echo $x; ?>" style="width: 400px;" value="<?php echo $link ? $link : 'http://'; ?>" />
					<div class="cls"></div>
				</div>
			<?php next($all); } ?>
			<div>
				<label>&nbsp;</label>
				<input type="submit" name="submit" id="submit" value="<?php echo $this->translate->_("Update Links"); ?>">
				<div class="cls"></div>
			</div>
		</form>
		<hr />
		<div class="left"><input onclick="Petolio.go(window.location.href.replace('links', 'pictures'));" type="button" value="<?php echo $this->translate->_("< Go Back to Pictures"); ?>" id="submit" name="prev" style="margin: 0px;" /><div class="clear"></div></div>
		<div class="right"><input onclick="Petolio.go(window.location.href.replace('links', 'finish'));" type="button" value="<?php echo $this->translate->_("Finish >"); ?>" id="submit" name="next"><div class="clear"></div></div>
		<div class="clear"></div>
	</div>
</div>
<script type="text/javascript">
	var Links = function() {
		var data = $('input[name^="item_"]')

		// constructor
		, __construct = function() {
			data.each(function(){
				var self = $(this);

				// bind focus
				self.bind('focus', function() {
					if(self.val() == 'http://' || self.val() == '<?php echo $this->translate->_("Name"); ?>')
						self.val('');
				});

				// bind blur
				self.bind('blur', function() {
					if(self.val() == '')
						self.val(self.hasClass('name') ? '<?php echo $this->translate->_("Name"); ?>' : 'http://');
				});
			});
		};

		// public, yay
		return {
			init: __construct
		}
	}();

	READY(Links.init);
</script>